package com.jyhs.maven.serlvet;



import com.jyhs.maven.Serice.impl.xtyhSericeImpl;
import com.jyhs.maven.Serice.xtyhSerice;
import com.jyhs.maven.entity.Zzjl;
import com.jyhs.maven.util.ReliesUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/tj")
public class Tj extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        xtyhSerice x = new xtyhSericeImpl();
        String Fname = req.getParameter("Fname");
        String sneme = req.getParameter("sneme");
        String bcm = req.getParameter("bcm");
        String baivs = req.getParameter("baivs");
        Zzjl z = new Zzjl();
        z.setFname(Fname);
        z.setSname(sneme);
        z.setSmcp(bcm);
        z.setZb(baivs);
        PrintWriter out = resp.getWriter();
        try {
            ReliesUtil.httuii( req,z);
            int i = x.addXtyhDao(z);
            if (i > 0) {
                req.getSession().setAttribute("Fin", z);
                resp.sendRedirect("html2.jsp");
            } else {
               out.println("添加失败！");
            }
//            $("#myButton").click(function () {
//                let b = $("#baivs").val();
//                if (b > 0 && b < v.baivs) {
//                    alert("提交成功")
//                    return 1;
//                } else {
//                    alert("余额不足！")
//                    return 0;
//                }
//            });

            out.flush();
            out.close();
        } catch (SQLException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
